package com.qzsoft.zhjd.laboratory.modules.asphaltCombustionFurnace.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.common.utils.ZhjdIotUtils;
import com.qzsoft.zhjd.laboratory.modules.asphaltCombustionFurnace.entity.AsphaltCombustionFurnaceEntity;
import com.qzsoft.zhjd.laboratory.modules.asphaltCombustionFurnace.service.AsphaltCombustionFurnaceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

/**
 * 燃烧法沥青含量测定仪（燃烧炉）
 *
 * @author sx
 * @email
 * @date 2023-07-11 18:44:52
 */
@RestController
@RequestMapping("laboratory/asphaltCombustionFurnace")
public class AsphaltCombustionFurnaceController {

    @Autowired
    private AsphaltCombustionFurnaceService asphaltCombustionFurnaceService;

    /**
     * 列表
     */
    @RequestMapping("/page")
    @RequiresPermissions("laboratory:asphaltCombustionFurnace:page")
    public Result page(@RequestParam Map<String, Object> params) {
        IPage page = asphaltCombustionFurnaceService.queryPage(params);
        return ResultUtils.ok(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/find/{id}")
    @RequiresPermissions("laboratory:asphaltCombustionFurnace:find")
    public Result find(@PathVariable("id") String id) {
        AsphaltCombustionFurnaceEntity asphaltCombustionFurnace = asphaltCombustionFurnaceService.getInfo(id);
        return ResultUtils.ok(asphaltCombustionFurnace);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("laboratory:asphaltCombustionFurnace:save")
    public Result save(@RequestBody AsphaltCombustionFurnaceEntity asphaltCombustionFurnace) {
        asphaltCombustionFurnaceService.saveData(asphaltCombustionFurnace);
        return ResultUtils.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("laboratory:asphaltCombustionFurnace:update")
    public Result update(@RequestBody AsphaltCombustionFurnaceEntity asphaltCombustionFurnace) {
        asphaltCombustionFurnaceService.updateData(asphaltCombustionFurnace);
        return ResultUtils.ok();
    }


    /**
     * 删除单个
     */
    @RequestMapping("/delete/{id}")
    @RequiresPermissions("laboratory:asphaltCombustionFurnace:delete")
    public Result deleteOne(@PathVariable("id") String id) {
        asphaltCombustionFurnaceService.deleteOneData(id);
        return ResultUtils.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("laboratory:asphaltCombustionFurnace:delete")
    public Result delete(@RequestBody String[] ids) {
        asphaltCombustionFurnaceService.deleteData(Arrays.asList(ids));
        return ResultUtils.ok();
    }

    /**
     * 解析数据
     *
     * @param deviceId
     * @param req
     * @return
     */
    @PostMapping("/parsingData/{deviceId}")
    public Result parsingData(@PathVariable("deviceId") String deviceId, HttpServletRequest req) {
        // System.out.println((new Date()) + "传入数据");
        asphaltCombustionFurnaceService.parsingData(ZhjdIotUtils.dataParsing(req), deviceId);
        return ResultUtils.ok();
    }

    /**
     * 解析数据
     * <p>
     * 北京大地龙华科技 - 燃烧法沥青含量测定仪（燃烧炉）HYRS-6
     *
     * @param deviceId 设备ID
     * @param request  请求
     * @since 20251106
     */
    @Deprecated
    @PostMapping("/parsingDataDDLH/{deviceId}")
    public String parsingDataDDLH(@PathVariable("deviceId") String deviceId, HttpServletRequest request) {
        return asphaltCombustionFurnaceService.parsingDataDDLH(ZhjdIotUtils.dataParsing(request), deviceId);
    }

    /**
     * 接收申克路业仪器有限公司的数据，
     * 济南至宁津四标段针入度；
     */
    @PostMapping("/data/entry")
    public Result dataEntry(@RequestBody JSONObject json) {
        asphaltCombustionFurnaceService.dataEntry(json);
        return ResultUtils.ok();
    }

}
